using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using Yoozoo.UI;
using Yoozoo.UI.YGUI;

public class RectTransformBinder : BinderBase
{
    public enum AttributeType : int
    {
        anchorMin,
        anchorMax,
        anchoredPosition,
        sizeDelta,
        pivot,
        anchoredPosition3D,
        offsetMin,
        offsetMax,
        position,
        localPosition,
        eulerAngles,
        localEulerAngles,
        right,
        up,
        forward,
        rotation,
        localRotation,
        localScale,
        hasChanged,
        hierarchyCapacity,
    }
    
    private RectTransform _target;
    
    public RectTransformBinder(UIExpansion owner, LinkerConfig config) : base(owner, config)
    {
    }

    public RectTransformBinder()
    {
        
    }

    public override void Dispose()
    {
        _target = null;
        base.Dispose();
    }

    public override void Init(LinkerConfig config)
    {
        GameObject targetGo = _owner.GetStoredGameObject(config.StoredGameObjectIndex);
        if (targetGo == null)
        {
            return;
        }
        _target = targetGo.GetComponent<RectTransform>();
        _active = _target != null;
    }
    public override void SetVector2(Vector2 value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.anchorMin:
                _target.anchorMin = value;
            break;
            case AttributeType.anchorMax:
                _target.anchorMax = value;
            break;
            case AttributeType.anchoredPosition:
                _target.anchoredPosition = value;
            break;
            case AttributeType.sizeDelta:
                _target.sizeDelta = value;
            break;
            case AttributeType.pivot:
                _target.pivot = value;
            break;
            case AttributeType.offsetMin:
                _target.offsetMin = value;
            break;
            case AttributeType.offsetMax:
                _target.offsetMax = value;
            break;
            default:
            break;
        }
        base.SetVector2(value);
    }
    
    public override void SetVector3(Vector3 value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.anchoredPosition3D:
                _target.anchoredPosition3D = value;
            break;
            case AttributeType.position:
                _target.position = value;
            break;
            case AttributeType.localPosition:
                _target.localPosition = value;
            break;
            case AttributeType.eulerAngles:
                _target.eulerAngles = value;
            break;
            case AttributeType.localEulerAngles:
                _target.localEulerAngles = value;
            break;
            case AttributeType.right:
                _target.right = value;
            break;
            case AttributeType.up:
                _target.up = value;
            break;
            case AttributeType.forward:
                _target.forward = value;
            break;
            case AttributeType.localScale:
                _target.localScale = value;
            break;
            default:
            break;
        }
        base.SetVector3(value);
    }
    
    public override void SetQuaternion(Quaternion value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.rotation:
                _target.rotation = value;
            break;
            case AttributeType.localRotation:
                _target.localRotation = value;
            break;
            default:
            break;
        }
        base.SetQuaternion(value);
    }
    
    public override void SetBoolean(bool value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.hasChanged:
                _target.hasChanged = value;
            break;
            default:
            break;
        }
        base.SetBoolean(value);
    }
    
    public override void SetInt32(int value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.hierarchyCapacity:
                _target.hierarchyCapacity = value;
            break;
            default:
            break;
        }
        base.SetInt32(value);
    }
    
}